package easy;

public class Solution_1275 {

    public String tictactoe(int[][] moves) {
        int[][] flags = new int[3][3];
        for (int i = 0; i < moves.length; i++) {
            if (i % 2 == 0) {
                flags[moves[i][0]][moves[i][1]] = 1;
            } else {
                flags[moves[i][0]][moves[i][1]] = 2;
            }
        }
        if ((flags[0][0] == flags[0][1] && flags[0][1] == flags[0][2] && flags[0][0] != 0)) {
            return flags[0][0] == 1 ? "A" : "B";
        } else if ((flags[1][0] == flags[1][1] && flags[1][1] == flags[1][2] && flags[1][0] != 0)) {
            return flags[1][0] == 1 ? "A" : "B";
        } else if ((flags[2][0] == flags[2][1] && flags[2][1] == flags[2][2] && flags[2][0] != 0)) {
            return flags[2][0] == 1 ? "A" : "B";
        } else if (flags[0][0] == flags[1][0] && flags[1][0] == flags[2][0] && flags[0][0] != 0) {
            return flags[0][0] == 1 ? "A" : "B";
        } else if (flags[0][1] == flags[1][1] && flags[1][1] == flags[2][1] && flags[0][1] != 0) {
            return flags[0][1] == 1 ? "A" : "B";
        } else if (flags[0][2] == flags[1][2] && flags[1][2] == flags[2][2] && flags[2][2] != 0) {
            return flags[0][2] == 1 ? "A" : "B";
        } else if (flags[0][0] == flags[1][1] && flags[1][1] == flags[2][2] && flags[0][0] != 0) {
            return flags[0][0] == 1 ? "A" : "B";
        } else if (flags[0][2] == flags[1][1] && flags[1][1] == flags[2][0] && flags[2][0] != 0) {
            return flags[0][2] == 1 ? "A" : "B";
        }
        return moves.length == 9 ? "Draw" : "Pending";
    }

    public static void main(String[] args) {
        Solution_1275 model = new Solution_1275();
        System.out.println(model.tictactoe(new int[][]{{1, 2}, {2, 1}, {1, 0}, {0, 0}, {0, 1}, {2, 0}, {1, 1}}));
        System.out.println(model.tictactoe(new int[][]{{0, 0}, {0, 1}, {2, 1}}));
        System.out.println(model.tictactoe(new int[][]{{0, 0}, {2, 0}, {1, 1}, {2, 1}, {2, 2}}));
        System.out.println(model.tictactoe(new int[][]{{0, 0}, {1, 1}, {0, 1}, {0, 2}, {1, 0}, {2, 0}}));
        System.out.println(model.tictactoe(new int[][]{{1, 1}}));
    }
}
